<template>
  <div>
  </div>
</template>

<script>
import { getOpenidByCode } from '@/api/allapis'
import Lockr from 'Lockr'

export default {
  name: 'WxAuth',
  components: {
  },
  data () {
    return {
      pageParams: {}
    }
  },
  computed: {
  },
  methods: {
    goJump () {
      let jump = Lockr.get('wxCodeJump')
      this.$router.push({name: 'Index'})
      this.$router.push({name: jump.name, params: jump.params, query: jump.query})
    }
  },
  async created () {
    const self = this
    self.$vux.loading.show({ text: '加载中' })
    if (self.$route.query.code) {
      let res = await getOpenidByCode(self.$route.query.code)
      self.$vux.loading.hide()
      console.log(res)
      // if (res.code === 1) {
      self.$store.commit('setOpenid', res.data)
      self.goJump() // 成功,跳转回去
      // }
    } else {
      self.$vux.toast.show({
        text: '微信授权失败',
        type: 'warn',
        time: 800
      })
    }
  }
}
</script>

<!-- 添加 "scoped" 属性, 只作用于当前文件内的样式 -->
<style lang="less" scoped>
</style>
